```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java Web核心技术：Filter与监听器</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
            background-color: #f9fafb;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        
        .transition-all {
            transition: all 0.3s ease;
        }
        
        .drop-cap:first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 0.8;
            margin: 0.2em 0.1em 0 0;
            color: #4f46e5;
            font-weight: bold;
        }
        
        .mermaid {
            background: white;
            padding: 1.5rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-2/3 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Java Web核心技术</h1>
                    <h2 class="text-2xl md:text-3xl font-semibold mb-6 text-indigo-100">Filter与监听器深度解析</h2>
                    <p class="text-lg md:text-xl mb-8 text-indigo-100 opacity-90">掌握Servlet规范中的两大核心技术，构建更安全、更高效的Web应用</p>
                    <div class="flex space-x-4">
                        <a href="#filter" class="bg-white text-indigo-600 px-6 py-3 rounded-lg font-medium hover:bg-indigo-50 transition-all shadow-md">探索Filter</a>
                        <a href="#listener" class="bg-indigo-800 text-white px-6 py-3 rounded-lg font-medium hover:bg-indigo-700 transition-all border border-indigo-700">了解监听器</a>
                    </div>
                </div>
                <div class="md:w-1/3">
                    <div class="bg-white bg-opacity-20 p-6 rounded-xl backdrop-blur-sm">
                        <div class="mermaid">
                            graph LR
                            A[Java Web核心技术] --> B(Filter)
                            A --> C(监听器)
                            B --> D[请求拦截]
                            B --> E[编码处理]
                            B --> F[权限控制]
                            C --> G[Session监听]
                            C --> H[Context监听]
                            C --> I[Request监听]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Filter Section -->
        <section id="filter" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="bg-indigo-100 p-3 rounded-lg mr-4">
                    <i class="fas fa-filter text-indigo-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">Filter过滤器</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-700 flex items-center">
                        <i class="fas fa-info-circle mr-2"></i> Filter概述
                    </h3>
                    <div class="drop-cap">
                        Filter是Sun公司在Servlet 2.3规范后增加的新功能，是Java EE中三大核心技术之一(Servlet、Listener、Filter)。通过javax.servlet.Filter接口可以实现对web资源的请求与响应进行拦截处理。
                    </div>
                    <p class="mt-4">
                        WEB开发人员通过Filter技术，可以对服务器管理的所有web资源（JSP、Servlet、静态文件等）进行拦截，实现URL级别的权限访问控制、敏感词过滤、响应压缩等高级功能。
                    </p>
                </div>
                
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-700 flex items-center">
                        <i class="fas fa-bolt mr-2"></i> 快速上手
                    </h3>
                    <ol class="list-decimal pl-5 space-y-2">
                        <li>创建一个类实现javax.servlet.Filter接口</li>
                        <li>实现接口中的方法</li>
                        <li>在web.xml文件中配置Filter</li>
                    </ol>
                    <div class="mt-4 p-4 bg-gray-50 rounded-lg">
                        <p class="text-sm text-gray-700">配置目的：</p>
                        <ul class="list-disc pl-5 mt-2 text-sm">
                            <li>指定拦截的资源</li>
                            <li>进行Filter初始化</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-700 flex items-center">
                        <i class="fas fa-recycle mr-2"></i> 生命周期
                    </h3>
                    <p class="mb-4">
                        Filter的生命周期由Web容器管理，包含三个阶段：
                    </p>
                    <ul class="list-disc pl-5 space-y-2">
                        <li>初始化阶段：Web容器调用init()方法</li>
                        <li>过滤阶段：每次请求时调用doFilter()方法</li>
                        <li>销毁阶段：Web容器调用destroy()方法</li>
                    </ul>
                </div>
                
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-700 flex items-center">
                        <i class="fas fa-lightbulb mr-2"></i> 应用场景
                    </h3>
                    <ul class="list-disc pl-5 space-y-2">
                        <li><strong>统一编码设置</strong>：解决请求/响应编码问题</li>
                        <li><strong>权限控制</strong>：对未登录用户进行访问限制</li>
                        <li><strong>日志记录</strong>：记录请求信息</li>
                        <li><strong>数据压缩</strong>：压缩响应内容</li>
                        <li><strong>敏感词过滤</strong>：过滤请求/响应中的敏感词汇</li>
                    </ul>
                </div>
            </div>
            
            <div class="mt-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800 border-b pb-2 flex items-center">
                    <i class="fas fa-project-diagram mr-2"></i> Filter核心概念导图
                </h3>
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <div class="mermaid">
                        graph TD
                            A[Filter] --> B[创建步骤]
                            B --> B1[实现Filter接口]
                            B --> B2[重写方法]
                            B --> B3[配置web.xml]
                            
                            A --> C[生命周期]
                            C --> C1[init]
                            C --> C2[doFilter]
                            C --> C3[destroy]
                            
                            A --> D[应用场景]
                            D --> D1[统一编码]
                            D --> D2[权限控制]
                            D --> D3[日志记录]
                            D --> D4[数据压缩]
                            D --> D5[敏感词过滤]
                            
                            A --> E[工作流程]
                            E --> E1[请求前处理]
                            E --> E2[放行chain.doFilter]
                            E --> E3[响应后处理]
                    </div>
                </div>
                <div class="mt-4 text-right">
                    <a href="https://www.yuque.com/attachments/yuque/0/2023/xmind/21449790/1692788687174-cbe07e7a-810c-42fa-9930-2fc02959336b.xmind" 
                       class="text-indigo-600 hover:text-indigo-800 text-sm flex items-center justify-end">
                        <i class="fas fa-download mr-1"></i> 下载完整导图
                    </a>
                </div>
            </div>
        </section>
        
        <!-- Listener Section -->
        <section id="listener" class="mb-20">
            <div class="flex items-center mb-10">
                <div class="bg-purple-100 p-3 rounded-lg mr-4">
                    <i class="fas fa-bell text-purple-600 text-2xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">监听器(Listener)</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-question-circle mr-2"></i> 什么是监听器
                    </h3>
                    <p class="drop-cap">
                        Java Web中的监听器用于监听Web核心对象的生命周期和属性变化，包括HttpServletRequest、HttpSession和ServletContext三大对象。通过监听器可以对这些对象创建、销毁及属性变更事件进行捕获和处理。
                    </p>
                </div>
                
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-tasks mr-2"></i> 监听器作用
                    </h3>
                    <ul class="list-disc pl-5 space-y-2">
                        <li>监听Web对象的创建与销毁</li>
                        <li>监听Web对象的属性变化</li>
                        <li>实现Session管理（如在线用户统计）</li>
                        <li>应用启动时资源初始化</li>
                        <li>请求日志记录与分析</li>
                    </ul>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-puzzle-piece mr-2"></i> 监听机制三要素
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-medium text-gray-800">1. 事件源</h4>
                            <p class="text-sm text-gray-600">产生事件的源头对象（如HttpSession）</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800">2. 注册监听</h4>
                            <p class="text-sm text-gray-600">将监听器与事件源绑定（通过web.xml配置）</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800">3. 监听器</h4>
                            <p class="text-sm text-gray-600">处理事件的对象（实现特定监听器接口）</p>
                        </div>
                    </div>
                </div>
                
                <div class="bg-white p-8 rounded-xl shadow-md card-hover transition-all">
                    <h3 class="text-xl font-semibold mb-4 text-purple-700 flex items-center">
                        <i class="fas fa-code mr-2"></i> 创建步骤
                    </h3>
                    <ol class="list-decimal pl-5 space-y-2">
                        <li>创建一个类实现指定的监听器接口</li>
                        <li>重写接口中的方法</li>
                        <li>在web.xml文件中配置监听器</li>
                    </ol>
                    <div class="mt-4 p-4 bg-gray-50 rounded-lg">
                        <p class="text-sm font-medium text-gray-700">常用监听器接口：</p>
                        <ul class="list-disc pl-5 mt-2 text-sm">
                            <li>ServletContextListener</li>
                            <li>HttpSessionListener</li>
                            <li>ServletRequestListener</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <div class="bg-white p-6 rounded-xl shadow-md card-hover transition-all">
                    <h4 class="font-semibold text-purple-700 mb-3 flex items-center">
                        <i class="fas fa-server mr-2"></i> ServletContext
                    </h4>
                    <p class="text-sm text-gray-700 mb-2">生命周期：</p>
                    <ul class="list-disc pl-5 text-sm space-y-1">
                        <li>创建：服务器启动时</li>
                        <li>销毁：服务器关闭时</li>
                    </ul>
                    <div class="mt-3 p-3 bg-purple-50 rounded-lg">
                        <p class="text-xs text-purple-800">适用场景：应用初始化、全局资源加载</p>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-md card-hover transition-all">
                    <h4 class="font-semibold text-purple-700 mb-3 flex items-center">
                        <i class="fas fa-user-clock mr-2"></i> HttpSession
                    </h4>
                    <p class="text-sm text-gray-700 mb-2">生命周期：</p>
                    <ul class="list-disc pl-5 text-sm space-y-1">
                        <li>创建：request.getSession()</li>
                        <li>销毁：超时(默认30分钟)或invalidate()</li>
                    </ul>
                    <div class="mt-3 p-3 bg-purple-50 rounded-lg">
                        <p class="text-xs text-purple-800">适用场景：用户会话跟踪、在线用户统计</p>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-xl shadow-md card-hover transition-all">
                    <h4 class="font-semibold text-purple-700 mb-3 flex items-center">
                        <i class="fas fa-exchange-alt mr-2"></i> HttpServletRequest
                    </h4>
                    <p class="text-sm text-gray-700 mb-2">生命周期：</p>
                    <ul class="list-disc pl-5 text-sm space-y-1">
                        <li>创建：请求到达时</li>
                        <li>销毁：响应完成后</li>
                    </ul>
                    <div class="mt-3 p-3 bg-purple-50 rounded-lg">
                        <p class="text-xs text-purple-800">适用场景：请求日志、请求耗时统计</p>
                    </div>
                </div>
            </div>
            
            <div class="mt-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800 border-b pb-2 flex items-center">
                    <i class="fas fa-project-diagram mr-2"></i> 监听器核心概念导图
                </h3>
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <div class="mermaid">
                        graph LR
                            A[监听器] --> B[按监听对象]
                            B --> B1[ServletContext]
                            B --> B2[HttpSession]
                            B --> B3[ServletRequest]
                            
                            A --> C[按事件类型]
                            C --> C1[生命周期]
                            C --> C2[属性变化]
                            
                            A --> D[应用场景]
                            D --> D1[在线人数统计]
                            D --> D2[系统初始化]
                            D --> D3[请求分析]
                            D --> D4[Session管理]
                            
                            A --> E[实现步骤]
                            E --> E1[实现接口]
                            E --> E2[重写方法]
                            E --> E3[配置web.xml]
                    </div>
                </div>
                <div class="mt-4 text-right">
                    <a href="https://www.yuque.com/attachments/yuque/0/2023/xmind/21449790/1692788706826-ee50684d-0d91-44a8-b492-3d7b17b26b1c.xmind" 
                       class="text-purple-600 hover:text-purple-800 text-sm flex items-center justify-end">
                        <i class="fas fa-download mr-1"></i> 下载完整导图
                    </a>
                </div>
            </div>
        </section>
        
        <!-- Comparison Section -->
        <section class="bg-white rounded-xl shadow-md p-8 mb-20">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 text-center">Filter与监听器对比</h2>
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">对比项</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-indigo-600 uppercase tracking-wider">Filter</th>
                            <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-purple-600 uppercase tracking-wider">Listener</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">主要功能</td>
                            <td class="px-6 py-4 whitespace-nowrap">拦截请求和响应</td>
                            <td class="px-6 py-4 whitespace-nowrap">监听对象生命周期和属性变化</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">接口</td>
                            <td class="px-6 py-4 whitespace-nowrap">javax.servlet.Filter</td>
                            <td class="px-6 py-4 whitespace-nowrap">多种（如ServletContextListener）</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">触发时机</td>
                            <td class="px-6 py-4 whitespace-nowrap">请求到达和响应返回时</td>
                            <td class="px-6 py-4 whitespace-nowrap">对象创建/销毁/属性变化时</td>
                        </tr>
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap font-medium text-gray-900">典型应用</td>
                            <td class="px-6 py-4 whitespace-nowrap">编码设置、权限控制、日志记录</td>
                            <td class="px-6 py-4 whitespace-nowrap">在线人数统计、系统初始化</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>
    </div>
    
    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">专注Java Web技术分享</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition-colors flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-8 border-t border-gray-800 text-center text-sm text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>
    
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```